import json

with open('json\data.json', 'r', encoding='utf-8') as f:
    data = json.load(f)

m = data['data']
with open('json\m.txt', 'w', encoding='utf-8') as f:
    for i in range(len(m) - 1, -1, -1):
        contents = m[i]['contents'][0]
        f.write(f"{contents['role']}：{contents['content']}" + '\n')
# print(['contents']['content'])